import Vue from 'vue'
import store from './store'
import App from './App'
import httpServer from './store/ajax.js'
import url from './store/config.js'
import navTo from './common/navTo.js'
import navLink from './common/navLink.js'
import {
	dianji
} from './static/js/stopclick.js'
import preventClick from './static/js/stopclick.js' // 根据自己的路径
import mixin from './store/mixin.js'
import navPublic from "@/components/navPublic.vue"

Vue.component("nav-public",navPublic);

import json from './Json.js' //测试用数据





/**
 *  因工具函数属于公司资产, 所以直接在Vue实例挂载几个常用的函数
 *  所有测试用数据均存放于根目录json.js
 *  
 *  css部分使用了App.vue下的全局样式和iconfont图标，有需要图标库的可以留言。
 *  示例使用了uni.scss下的变量, 除变量外已尽量移除特有语法,可直接替换为其他预处理器使用
 */
const msg = (title, duration = 3000, mask = false, icon = 'none') => {
	//统一提示方便全局修改
	if (Boolean(title) === false) {
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}
// const json = type=>{
// 	//模拟异步请求数据
// 	return new Promise(resolve=>{
// 		setTimeout(()=>{
// 			resolve(Json[type]);
// 		}, 500)
// 	})
// }

const prePage = () => {
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 2];
	return prePage.$vm;
}
const prePage3 = () => {
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 4];
	return prePage.$vm;
}

Vue.config.productionTip = false
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;
Vue.prototype.$api = {
	msg,
	json,
	prePage,
	prePage3
};
Vue.prototype.$axios = httpServer;
Vue.prototype.$url = url;
Vue.prototype.$navTo = navTo;
Vue.prototype.$navRed = navLink.navRed;
Vue.prototype.$navBack = navLink.navBack;
// const accountInfo = uni.getAccountInfoSync();
// uni.setStorageSync('ver', accountInfo.miniProgram.version);
Vue.use(preventClick);
Vue.mixin(mixin);

// #ifdef H5  
import wechat from 'common/SDK/wechat'
if (wechat.isWechat()) {
	Vue.prototype.$wechat = wechat;
}
// #endif  
Vue.prototype.$onLaunched = new Promise(resolve => {
	Vue.prototype.$isResolve = resolve
})

App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()